def aboba(g):
    g = int(g)
    d = 2
    while d < g:
        if g % d == 0:
            return False
        else:
            d += 1
    if d == g:
        return True

n = int(input())
if 999 < n <9999:
    n1 = n % 1000
    n2 = n // 10
    n3 = n // 100
    n4 = n % 100 #n5
    n5 = n % 10
    n6 = n % 1000 // 100
    n7 = n // 1000
    n8 = n % 1000 // 10
    n9 = n // 10 % 10
    f = 0
    if aboba(n) and n > f:
        f = n
    if aboba(n1) and n1 > f:
        f = n1
    if aboba(n2) and n2 > f:
        f = n2
    if aboba(n3) and n3 > f:
        f = n3
    if aboba(n4) and n4 > f:
        f = n4
    if aboba(n5) and n5 > f:
        f = n5
    if aboba(n6) and n6 > f:
        f = n6
    if aboba(n7) and n7 > f:
        f = n7
    if aboba(n8) and n8 > f:
        f = n8
    if aboba(n9) and n9 > f:
        f = n9
    print(f)
else:
    print(0)
